home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
indents.zip
/
io.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-30
|
23KB
|
679 lines
/**
* Copyright (c) 1985 Sun Microsystems, Inc.
* Copyright (c) 1980 The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted provided
* that the above copyright notice and this paragraph are duplicated in all
* such forms and that any documentation, advertising materials, and other
* materials related to such distribution and use acknowledge that the
* software was developed by the University of California, Berkeley, the
* University of Illinois, Urbana, and Sun Microsystems, Inc. The name of
* either University or Sun Microsystems may not be used to endorse or
* promote products derived from this software without specific prior written
* permission. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
* OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "globals.h"
#ifndef lint
# ifndef ANSIC
static char sccsid[] = "@(#)io.c 6.0 (Berkeley) 92/06/15";
# endif /* ANSIC */
#endif /* not lint */
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#ifdef ANSIC
# include <stdarg.h>
# define bzero(achBuf, cbLength) memset(achBuf, 0, cbLength)
static int pad_output(int, int);
#endif /* ANSIC */
static int comment_open = 0;
static int paren_target = 0;
/* dump_line is the routine that actually effects the printing of the new
* source. It prints the label section, followed by the code section with the
* appropriate nesting level, followed by any comments
*/
#ifdef ANSIC
void dump_line(void)
#else /* ANSIC */
void dump_line()
#endif /* ANSIC */
{
register int cur_col;
register int target_col;
static int not_first_line = 0; /* = 0 ? PETER */
if (ps.procname[0]) {
if (troff) {
if (comment_open) {
comment_open = 0;
fprintf(output, ".*/\n");
}
fprintf(output, ".Pr \"%s\"\n", ps.procname);
}
ps.ind_level = 0;
ps.procname[0] = 0;
}
if (s_code == e_code && s_lab == e_lab && s_com == e_com) {
if (suppress_blanklines > 0)
suppress_blanklines--;
else {
ps.bl_line = true;
n_real_blanklines++;
}
} else if (!inhibit_formatting) {
suppress_blanklines = 0;
ps.bl_line = false;
if (prefix_blankline_requested && not_first_line)
if (swallow_optional_blanklines) {
if (n_real_blanklines == 1)
n_real_blanklines = 0;
} else {
if (n_real_blanklines == 0)
n_real_blanklines = 1;
}
while (--n_real_blanklines >= 0)
putc('\n', output);
n_real_blanklines = 0;
if (ps.ind_level == 0) {
if (!btype_3)
ps.ind_stmt = 0;/* this is a class A kludge. don't do
* additional statement indentation if we are
* at bracket level 0 */
else if (*s_code != '{')
ps.ind_stmt = 0;/* this one is a class AA kludge: defeat the
* class A kludge if the statement is '{' */
}
if (e_lab != s_lab || e_code != s_code)
++code_lines; /* keep count of lines with code */
if (e_lab != s_lab) { /* print lab, if any */
if (comment_open) {
comment_open = 0;
fprintf(output, ".*/\n");
}
while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
e_lab--;
cur_col = pad_output(1, compute_label_target());
fprintf(output, "%.*s", e_lab - s_lab, s_lab);
cur_col = count_spaces(cur_col, s_lab);
} else
cur_col = 1; /* there is no label section */
ps.pcase = false;
if (s_code != e_code) { /* print code section, if any */
register char *p = NULL;
if (comment_open) {
comment_open = 0;
fprintf(output, ".*/\n");
}
target_col = compute_code_target();
{
register int i;
for (i = 0; i < ps.p_l_follow; i++)
if (ps.paren_indents[i] >= 0)
ps.paren_indents[i] = -(short) (ps.paren_indents[i] + target_col);
}
cur_col = pad_output(cur_col, target_col);
for (p = s_code; p < e_code; p++)
if (*p == (char) 0200)
fprintf(output, "%d", target_col * 7);
else
putc(*p, output);
cur_col = count_spaces(cur_col, s_code);
}
if (s_com != e_com)
if (troff) {
int all_here = 0;
register char *p = NULL;
if (ps.cc_comment)
all_here++;
else if (e_com[-1] == '/' && e_com[-2] == '*')
e_com -= 2, all_here++;
while (e_com > s_com && e_com[-1] == ' ')
e_com--;
*e_com = 0;
p = s_com;
while (*p == ' ')
p++;
if (p[0] == '/' && (p[1] == '*' || p[1] == '/'))
p += 2, all_here++;
else if (p[0] == '*')
p += p[1] == '/' ? 2 : 1;
while (*p == ' ')
p++;
if (*p == 0)
goto inhibit_newline;
if (comment_open < 2 && ps.box_com) {
comment_open = 0;
fprintf(output, ".*/\n");
}
if (comment_open == 0) {
if ('a' <= *p && *p <= 'z')
*p += 'A' - 'a';
if (e_com - p < 50 && all_here == 2) {
register char *follow = p;
fprintf(output, "\n.nr C! \\w\1");
while (follow < e_com) {
switch (*follow) {
case '\n':
putc(' ', output);
case 1:
break;
case '\\':
putc('\\', output);
default:
putc(*follow, output);
}
follow++;
}
putc(1, output);
}
fprintf(output, "\n./* %dp %d %dp\n",
ps.com_col * 7,
(s_code != e_code || s_lab != e_lab) - ps.box_com,
target_col * 7);
}
comment_open = 1 + ps.box_com;
while (*p) {
if (*p == BACKSLASH)
putc(BACKSLASH, output);
putc(*p++, output);
}
} else { /* print comment, if any */
register int target = ps.com_col;
register char *com_st = s_com;
target += ps.comment_delta;
while (*com_st == '\t')
com_st++, target += tabsize; /* JHT 22oct89 */
while (target <= 0)
if (*com_st == ' ')
target++, com_st++;
else if (*com_st == '\t') {
target += (tabsize - ((target - 1) % tabsize)); /* JHT 22oct89 */
com_st++;
} else